package com.seelyn.ddvideo.web;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.mail.internet.MimeMessage;

@RestController
@RequestMapping("mail")
public class MailController {

    private Logger LOG = LoggerFactory.getLogger(MailController.class);
    @Autowired
    JavaMailSender mailSender;

    @RequestMapping("sendemail")
    public View<String> sendEmail() {
        View<String> result = new View<>();
        try {
            final MimeMessage mimeMessage = this.mailSender.createMimeMessage();
            final MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
            message.setFrom("237242115@qq.com");
            message.setTo("283815609@qq.com");
            message.setSubject("测试邮件主题");
            message.setText("测试邮件内容");
            this.mailSender.send(mimeMessage);
            result.setCode(View.OK);
            return result;
        } catch (Exception ex) {
            LOG.error(ex.getMessage(), ex);
            result.setCode(View.ERROR);
            return result;
        }
    }
}  